#include <stdio.h>

void decimalToHex(unsigned int n) {
    char hexChars[] = "0123456789ABCDEF";
    char hexStr[9]; 
    int index = 0;


    if (n == 0) {
        hexStr[index++] = '0';
        hexStr[index] = '\0';
    } else {
        
        unsigned int remainder;
        do {
            remainder = n % 16;
            hexStr[index++] = hexChars[remainder];
            n /= 16;
        } while (n != 0);
    }

    
    for (int i = 0; i < index / 2; i++) {
        char temp = hexStr[i];
        hexStr[i] = hexStr[index - i - 1];
        hexStr[index - i - 1] = temp;
    }


    hexStr[index] = '\0';

   
    printf("%s\n", hexStr);
}

int main() {
    unsigned int decimalNum;

    printf("请输入一个十进制数（输入0结束）: ");
    while (scanf("%u", &decimalNum) == 1 && decimalNum != 0) {
        decimalToHex(decimalNum);
        printf("请输入下一个十进制数（输入0结束）: ");
    }

    printf("程序结束。\n");
    return 0;
}